import time

from appium import webdriver
from appium.webdriver.common.mobileby import  MobileBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium.webdriver.common.touch_action import TouchAction
cap_dict = {
    "deviceName":"127.0.0.1:62001",
    "platformName":"Android",
    "platformVersion":"7.1.2",
    "appPackage":"com.lingyue.zebraloan",
    "appActivity":"com.lingyue.banana.activities.BananaLaunchActivity"
}
# 初始化驱动
driver = webdriver.Remote("http://localhost:4723/wd/hub",cap_dict)
# 设置隐式等待
driver.implicitly_wait(15)

# 479,991
time.sleep(2)
TouchAction(driver).tap(x=479,y=991).perform()
"""
点击是瞬发的，一定要加一个等待，不然页面还加载出来，直接就点击了
tap：点击x是479的，y是991
perform：执行这一组动作
"""
time.sleep(10)
# 点击用户故事
WebDriverWait(driver,10,0.5).\
    until(EC.presence_of_all_elements_located((MobileBy.ID,"com.lingyue.zebraloan:id/iv_card")))[3].\
    click()
# 等待页面
time.sleep(3)
# 点击第二个 345,898
TouchAction(driver).tap(x=345,y=898).perform()
# 等待页面
time.sleep(2)

# 492,1412  601,382
TouchAction(driver).press(x=492,y=1412).move_to(x=601,y=382).release().perform()
"""
press：从开始的地方移动
move_to：移动到哪里
release()：松开手指
perform()：执行这一组动作
"""
# 获取用户故事
time.sleep(1)
text = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((MobileBy.ID,"com.lingyue.zebraloan:id/tv_title"))).text
assert text == "用户故事"






